﻿using Appliaction.Dto.Inv;
using Appliaction.IAppServices.Inv;
using AutoMapper;
using Domain.Entitys.Base_Manage;
using EFCore.Repositorys.Inv;
using Microsoft.AspNetCore.Mvc;


    namespace API.Controllers.Inv
    {
        [Route("api/[controller]/[action]")]
        [ApiController]
        //[Authorize]
        public class Inv_othwrController : Controller
        {
           private readonly IMapper _mapper;
           private readonly IInv_othwrServices _inv_othwrService;

            public Inv_othwrController(IInv_othwrServices inv_othwrService, IMapper mapper)
            {
                _inv_othwrService = inv_othwrService;
                _mapper = mapper;
            }

            /// <summary>
            /// 分页查询
            /// </summary>
            /// <param name="searchKeyword"></param>
            /// <param name="othoutord_type"></param>
            /// <param name="currentPage"></param>
            /// <param name="pageSize"></param>
            /// <returns></returns>
            /// <exception cref="NotImplementedException"></exception>
            [HttpGet]
            public JsonResult GetOthwrWithDetailsAsyncCon(string ? searchKeyword, string ? othwr_type, int currentPage, int pageSize)
            {
                return new JsonResult(_inv_othwrService.GetOthwrWithDetailsAsync(searchKeyword, othwr_type, currentPage, pageSize));
            }
            /// <summary>
            /// 查询总数
            /// </summary>
            /// <param name="searchKeyword"></param>
            /// <param name="othoutord_type"></param>
            /// <returns></returns>
            /// <exception cref="NotImplementedException"></exception>
            [HttpGet]
            public Task<int> GetTotalCountAsyncCon(string ? searchKeyword, string ? othwr_type)
            {
                return _inv_othwrService.GetTotalCountAsync(searchKeyword, othwr_type);
            }

        /// <summary>
        /// 根据其他入库单编号查询其他入库单详情信息
        /// </summary>
        /// <param name="Othwr_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<JsonResult> inv_OthwrproddtlSelecControllert(string Othwr_code)
        {
            var result = await _inv_othwrService.inv_OthwrproddtlSelect(Othwr_code);
            return new JsonResult(result);
        }


        /// <summary>
        /// 查看数据字典
        /// </summary>
        /// <param name="dict_value"></param>
        /// <param name="dict_type"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<string> dict_dataSelect(string dict_value, string dict_type)
        {
            return _inv_othwrService.dict_data_Select(dict_value, dict_type);
        }



        /// <summary>
        /// 查询数据字典
        /// </summary>
        /// <param name="dict_value"></param>
        /// <param name="dict_type"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<List<Sys_Dict_Data>> inv_othwrSelect_Data(string dict_value, string dict_type)
        {
          return _inv_othwrService.inv_othwr_SelectData(dict_value, dict_type);
        }
        /// <summary>
        /// 查询仓库信息
        /// </summary>
        /// <param name="Othwr_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<JsonResult> inv_othwr_Select_Weahouse(string Othwr_code)
        {
            var result = await _inv_othwrService.inv_othwr_SelectWeahouse(Othwr_code);
            return new JsonResult(result);
        }


   
        /// <summary>
        /// 根据单据编号查询 其他入库单信息的id,来添加详情    
        /// </summary>
        /// <param name="otgwr_code"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> InvOthwrproddtlSelect_id(string otgwr_code)
        {

           return _inv_othwrService.inv_OthwrproddtlSelect_id(otgwr_code);
        }



        /// <summary>
        /// 库存调拨查询
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public JsonResult Inv_othwralltrf()
        {
            return new JsonResult(_inv_othwrService.Inv_othwrall_trf());
        }
        /// <summary>
        /// 库存盘点查询
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public JsonResult Inv_othwrallqty()
        {
            return new JsonResult(_inv_othwrService.Inv_othwrall_qty());
        }



        /// <summary>
        /// 添加其他入库单
        /// </summary>
        /// <param name="inv_OthwrAdd"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_othwr_Insert(Inv_othwrAddDto inv_OthwrAdd)
        {
            return _inv_othwrService.Inv_othwr_Insert(inv_OthwrAdd);
        }

        /// <summary>
        /// 添加其他入库单详情表的信息
        /// </summary>
        /// <param name="inv_Othwrproddtl"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<IActionResult> Inv_othproddetails(
       [FromBody] List<Inv_othwrproddtlAddDto> inv_OthwrproddtlAddDtoList)
        {
            try
            {
                int result = await _inv_othwrService.Inv_othproddetails(inv_OthwrproddtlAddDtoList);
                return Ok(new { success = true, count = result });
            }
            catch (Exception ex)
            {
                return StatusCode(500, new { success = false, error = ex.Message });
            }
        }



        /// <summary>
        /// 删除其他入库单
        /// </summary>
        /// <param name="othwr_id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_othwr_delete(int othwr_id)
        {
            return _inv_othwrService.Inv_othwr_delete(othwr_id);
        }



        /// <summary>
        /// 修改其他入库单审核信息
        /// </summary>
        /// <param name="othwr_code"></param>
        /// <param name="Othwr_audit_by"></param>
        /// <param name="Othwr_audit_time"></param>
        /// <param name="othwr_audit_statua"></param>
        /// <param name="othwr_audit_opinion"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<int> Inv_othwr_examineUpdate(Inv_Update_othwrtDto inv_Update_OthwrtDto)
        {
            return _inv_othwrService.Inv_othwr_examineUpdate(inv_Update_OthwrtDto);
        }



        /// <summary>
        /// 修改入库单和同一时间执行添加修改入库单详情
        /// </summary>
        /// <param name="inv_OthwrUpdateDto"></param>
        /// <param name="entities"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<JsonResult> Inv_othwr_Update([FromBody] Inv_othwrUpdateMerge inv_OthwrUpdateMerge)
        {
            if (inv_OthwrUpdateMerge == null)
            {
                return new JsonResult(new { code = 0, msg = "参数为空" });
            }
            return new JsonResult(await _inv_othwrService.Inv_othwr_Update(inv_OthwrUpdateMerge));
        }



        /// <summary>
        ///  根据入库单号去修改入库单的状态
        /// </summary>
        /// <param name="othwr_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_othwr_Update_othwr_staus(string othwr_code)
        {
            return _inv_othwrService.Inv_othwr_Update_othwr_staus(othwr_code);
        }


        /// <summary>
        ///  根据入库单号去修改入库单的状态--判断,期初
        /// </summary>
        /// <param name="othwr_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_othwr_Update_othwr_staus_pd(string othwr_code)
        {
            return _inv_othwrService.Inv_othwr_Update_othwr_staus_pd(othwr_code);
        }
    }
    }
